/*
 * @lc app=leetcode id=496 lang=cpp
 *
 * [496] Next Greater Element I
 */

// @lc code=start
class Solution {
public:
    vector<int> nextGreaterElement(vector<int>& nums1, vector<int>& nums2) {

        vector<int> next(nums2.size(), -1);
        unordered_map<int, int> table(nums2.size());
        for (int i = 0; i < nums2.size(); ++i) {
            table[nums2[i]] = i;
            for (int j = 0; j < i; ++j) {
                if (next[j] == -1 && nums2[i] > nums2[j]){
                    next[j] = nums2[i];
                }
            }
        }

        vector<int> res(nums1.size(), -1);
        for (int i = 0; i < nums1.size(); ++i) {
           auto idx = table[nums1[i]];
           res[i] = next[idx];
           
        }
        return res;
 

    }
};
// @lc code=end

